define(['text!./info.html', 'css!./info.css','APPdate'], function( html) {
	avalon.templateCache['info']=html;
	var vm = avalon.define({
	    $id: "info",
	    tag:1,
	    headphoto:'',
	    name:'',
	    birthday:'',
	    phone:'',
	    tel:'',
	    emPhone:'',
	    sex:'',
	    changeTag:function(){
	    	vm.tag=2;
	    },
	    choiceDate:function(id){
	    	date(id);
	    },
	    changeSex:function(){
	    	var index=$(this).index();
	    	$(this).addClass('current').siblings().removeClass('current');
	    	vm.sex=index;
	    },
	    back:function(){
	    	Router.go('/setup/setup')
	    },
	    save:function(){
	    	var user=JSON.parse(getstorage('user'));
	    	if(vm.sex=='男'||vm.sex=='女'){
	    		var sex=vm.sex=='男'?1:0;
	    	}else if(vm.sex==1||vm.sex==0){
	    		var sex=vm.sex;
	    	}
	    	if(!user.height){
	    		var height='';
	    	}else{
	    		var height=user.height;
	    	}
	    	if(!user.weight){
	    		var weight='';
	    	}else{
	    		var weight=user.weight;
	    	}
	    	httpPost('user/updateUser', {
				type: 0,//更新
				userId: user.idu,//用户id
				name: vm.name,
				password:user.password,
				birthday:$('#date').val(), //生日
				sex: sex, //性别 1：男，0：女
				phone: vm.phone, //手机号码
				tel: vm.tel, //座机号码
				emPhone: vm.emPhone, //紧急联系电话
				user_id: user.user_id, //所属家人id
				refreshToken: user.refreshToken,
				height: height, //身高
				weight: weight, //体重
				unionid: user.unionid,
				deviceId: user.deviceId, //移动设备id
				deviceinfo: user.deviceinfo, //1：iOS，0：Android
				status: "1", //0：删除，1：有效
				headphoto: user.headphoto //头像base64编码
			}).done(function(data) {
				if("200" == data.code) {
					setstorage('user',data.user);
					vm.sex=data.user.sex=='1'?'男':'女';
					msgbox('提示','保存成功');
					vm.tag=1;
				} else {
					msgbox('提示',data.msg);
				}
			});
	   },
	    init:function(){
	    	if(getstorage('user')){
	    		var user=JSON.parse(getstorage('user'));
	    		vm.headphoto=user.headphoto;
	    		vm.name=user.userName;
	    		vm.birthday=user.birthday;
	    		vm.phone=user.phone;
	    		vm.tel=user.tel;
	    		vm.emPhone=user.emPhone;
	    		vm.sex=user.sex=='1'?'男':'女';
	    		if(user.sex=='1'){
	    			$('#sex button').eq(1).addClass('current');
	    		}else{
	    			$('#sex button').eq(0).addClass('current');
	    		}
	    	}
	    	vm.tag=1;
	    }
  });
});
//选择孩子的出生年月
function date(el) {
	appDateField = new APPDateField(el, {
		title: '请选择日期',
		isCN: true,
		commer: '-',
		upYear: 500,
		downYear: 0,
		showTime: false,
		complete: function() {
			console.log(this.getCurrentDate());
		},
		cancel: function() {
			console.log('[已取消]  Cancel----');
		}
	});
}

function check(){
	
}
